import db from './db'
import Mock from 'mockjs'

Mock.mock('admin/register', 'post', ({ body }) => {
  const { username, password } = JSON.parse(body)

  const reslut = db.select('Oppo_admin', item => {
    return item.username === username
  })
  if (reslut && reslut.length > 0) {
    return { err: 101, desc: '抱歉，该用户名存在' }
  }
  db.add('Oppo_admin', { username, password, state: 0 })
  return {
    err: 0,
    desc: '执行成功'
  }
})
